﻿using UnityEngine;
using UnityEngine.AI;

namespace Level.Enemies
{
    public class BombMove : MonoBehaviour
    {
        private bool _active = true;

        private Transform _heroTransform;
        [SerializeField] private NavMeshAgent _agent;

        public void Construct(Transform heroTransform) =>
            _heroTransform = heroTransform;

        public void Stop()
        {
            _active = false;
            if (!_agent) 
                return;
            _agent.speed = 0;
            _agent.enabled = false;
        }

        private void FixedUpdate()
        {
            if (_active)
                _agent.destination = _heroTransform.position;
        }
    }
}